import { reqAttrInfo, reqSaveAttrInfo, reqDeleteAttr } from '@/api/attr'
const state = {
    attrList: []
}
const mutations = {
    SET_ATTRLIST(state, attrList) {
        state.attrList = attrList
    },
    CLEAR_ATTRLIST(state) {
        state.attrList = []
    }
}
const actions = {
    // 获取属性列表
    async getAttrInfoList({ commit }, { category1Id, category2Id, category3Id }) {
        try {
            const res = await reqAttrInfo(category1Id, category2Id, category3Id)
            commit('SET_ATTRLIST', res.data)
        } catch (error) {
            Message.error('获取列表信息失败')
        }
    },
    clearAttrList({ commit }) {
        commit('CLEAR_ATTRLIST')
    },
    // 保存新增属性或修改的属性
    async saveAddorEditAttr({ commit }, attrParams) {
        try {
            await reqSaveAttrInfo(attrParams)
            return 'ok'
        } catch (error) {
            return Promise.reject('fail')
        }
    },
    // 删除某个attr
    async deletOneAttr({ commit }, attrId) {
        try {
            await reqDeleteAttr(attrId)
        } catch (error) {
            return Promise.reject('fail')
        }
    }
}
const getters = {

}
export default {
    namespaced: true,
    state,
    mutations,
    actions,
    getters
}